package edu.humc.service.Impl;

import edu.humc.dao.MessageTableMapper;
import edu.humc.pojo.MessageTable;
import edu.humc.pojo.Recycle;
import edu.humc.service.MessageTableService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("MessageTableServiceImpl")
public class MessageTableServiceImpl implements MessageTableService {
    @Resource(name = "MessageTableMapper")
    MessageTableMapper messageTableMapper;
    public boolean AddMessage(MessageTable messageTable) {
        if (messageTableMapper.AddMessage(messageTable)>0) {
            return true;
        }
        return false;
    }

    @Override
    public List<MessageTable> SelectMessage(int id) {
        return messageTableMapper.SelectMessage(id);
    }
//    删除留言

    @Override
    public boolean DeleteMessage(String mid) {
        if(messageTableMapper.DeleteMessage(mid)>0){
            return true;
        }
        return false;
    }

//    展示留言详情

    @Override
    public MessageTable DisplayDetail(String mid) {
        return messageTableMapper.DisplayDetail(mid);
    }
//    修改留言信息

    @Override
    public boolean UpdateMessage(MessageTable messageTable) {
        if (messageTableMapper.UpdateMessage(messageTable)>0) {
            return true;
        }
        return false;
    }

//    添加回收站操作

    @Override
    public int AddRecycle(MessageTable messageTable) {
        //        获取留言发表日期
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//        删除日期生成
        String delete_date=formatter.format(date);
        System.out.println(delete_date);
        System.out.println(messageTable);
        Recycle recycle=new Recycle();
        recycle.setMid(messageTable.getMid());
        recycle.setMdate(messageTable.getMdate());
        recycle.setMtype(messageTable.getMtype());
        recycle.setMtitle(messageTable.getMtitle());
        recycle.setMcontent(messageTable.getMcontent());
        recycle.setId(messageTable.getId());
        recycle.setDelete_date(delete_date);
        System.out.println(recycle);
        int result=messageTableMapper.AddRecycle(recycle);
//        int result=messageTableMapper.AddRecycle(messageTable,delete_date);
        System.out.println(result);
        return result;
    }
}
